package com.cookiesoft.activity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cookiesoft.common.annotation.Log;
import com.cookiesoft.common.core.controller.BaseController;
import com.cookiesoft.common.core.domain.AjaxResult;
import com.cookiesoft.common.enums.BusinessType;
import com.cookiesoft.activity.domain.ZhenCdkey;
import com.cookiesoft.activity.service.IZhenCdkeyService;
import com.cookiesoft.common.utils.poi.ExcelUtil;
import com.cookiesoft.common.core.page.TableDataInfo;

/**
 * 礼包码Controller
 *
 * @author anc
 * @date 2024-11-06
 */
@CrossOrigin
@RestController
@RequestMapping("/activity/gift" )
public class ZhenCdkeyController extends BaseController {
    @Autowired
    private IZhenCdkeyService zhenCdkeyService;

/**
 * 查询礼包码列表
 */
@PreAuthorize("@ss.hasPermi('activity:gift:list')" )
@GetMapping("/list" )
    public TableDataInfo list(ZhenCdkey zhenCdkey) {
        startPage();
        List<ZhenCdkey> list = zhenCdkeyService.selectZhenCdkeyList(zhenCdkey);
        return getDataTable(list);
    }

    /**
     * 导出礼包码列表
     */
    @PreAuthorize("@ss.hasPermi('activity:gift:export')" )
    @Log(title = "礼包码" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ZhenCdkey zhenCdkey) {
        List<ZhenCdkey> list = zhenCdkeyService.selectZhenCdkeyList(zhenCdkey);
        ExcelUtil<ZhenCdkey> util = new ExcelUtil<ZhenCdkey>(ZhenCdkey. class);
        util.exportExcel(response, list, "礼包码数据" );
    }

    /**
     * 获取礼包码详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:gift:query')" )
    @GetMapping(value = "/{cdkeyId}" )
    public AjaxResult getInfo(@PathVariable("cdkeyId" ) Long cdkeyId) {
        return success(zhenCdkeyService.selectZhenCdkeyByCdkeyId(cdkeyId));
    }

    /**
     * 新增礼包码
     */
    @PreAuthorize("@ss.hasPermi('activity:gift:add')" )
    @Log(title = "礼包码" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhenCdkey zhenCdkey) {
        return toAjax(zhenCdkeyService.insertZhenCdkey(zhenCdkey));
    }

    /**
     * 修改礼包码
     */
    @PreAuthorize("@ss.hasPermi('activity:gift:edit')" )
    @Log(title = "礼包码" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhenCdkey zhenCdkey) {
        return toAjax(zhenCdkeyService.updateZhenCdkey(zhenCdkey));
    }

    /**
     * 删除礼包码
     */
    @PreAuthorize("@ss.hasPermi('activity:gift:remove')" )
    @Log(title = "礼包码" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{cdkeyIds}" )
    public AjaxResult remove(@PathVariable Long[] cdkeyIds) {
        return toAjax(zhenCdkeyService.deleteZhenCdkeyByCdkeyIds(cdkeyIds));
    }
}
